<?php


namespace app\dao;


use app\model\Category;
use think\facade\Cache;
use think\Model;

class CategoryDao
{
/*
    public function get($id)
    {
        $key = 'dao_category_id_'.$id;
        $c = new Category();
        $redis = Cache::store('redis');
        echo $redis;
        $r = $redis->get($key);
        if ($r == null) {
            $r = $c->where('id', '=', $id)->find();
        }
        $redis->set($key, $r);
        return $r;

    }*/

    public function getByCode($code)
    {
        $key = 'kdm:dao:category_code_'.$code;
        $redis = Cache::store('file');

        $r = $redis->get($key);
        if ($r != null) {
            echo '<!--CategoryDao:缓存命中-->';
            return $r;
        }
        $c = new Category();
        $r = $c->where('code', '=', $code)->find();
        $redis->set($key, $r);
        echo '<!--CategoryDao:加载数据到缓存-->';

        return $r;

    }
}